/*
 * WaveGen.java
 *
 * Created on January 19, 2008, 5:45 PM
 * 
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package hextd;

/**
 *
 * @author  hylke
 */
public class WaveGen extends javax.swing.JApplet {
    private String[] enemies = {"yr", "rr", "gp", "ff", "hh", "bb", "ss", "prp"};
    private String[] mods = {"N", "N", "N", "S", "L"};
    /**
     * Initializes the applet WaveGen
     */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                    jSpinner_paths.setValue(1);
                    jTextField_healthStart.setText(""+225);
                    jTextField_healthGrowthStart.setText(""+1.15);
                    jTextField_healthGrowthEnd.setText(""+1.45);
                    jSpinner_moneyStart.setValue(1);
                    jSpinner_moneyIncStart.setValue(1);
                    jSpinner_moneyIncEnd.setValue(10);
                    jSpinner_waves.setValue(69);
                    jSpinner_nrEnemies.setValue(15);
                    jSpinner_bonus.setValue(5);
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    
    private void generate() {
        int paths = new Integer(this.jSpinner_paths.getValue().toString()).intValue();
        int wave = 1;
        int waveNr = new Integer(this.jSpinner_waves.getValue().toString()).intValue();
        float money = new Integer(this.jSpinner_moneyStart.getValue().toString()).intValue();
        int moneyIncStart = new Integer(this.jSpinner_moneyIncStart.getValue().toString()).intValue();;
        int moneyIncEnd = new Integer(this.jSpinner_moneyIncEnd.getValue().toString()).intValue();;
        float moneyInc = moneyIncStart;
        int nr = new Integer(this.jSpinner_nrEnemies.getValue().toString()).intValue();
        int bonus = new Integer(this.jSpinner_bonus.getValue().toString()).intValue();
        int pick = 0;
        double hp = new Double(this.jTextField_healthStart.getText()).doubleValue();
        double growthStart = new Double(this.jTextField_healthGrowthStart.getText()).doubleValue();
        double growthEnd = new Double(this.jTextField_healthGrowthEnd.getText()).doubleValue();
        double growth = growthStart;
        
        String s = "";
        int mod = 0;
        for (int i=1; i<=waveNr; i++) {
            s += "wave "+Math.round(hp)+" "+Math.round(money)+"\n";
            for (int p=0; p<paths; p++) {
                if (i%bonus==0) {
                    if (p==0) {
                        s += ""+(nr-1)+" hg pep\n";
                    } else {
                        s += ""+nr+" hg\n";
                    }
                } else {
                    mod = (int)Math.round(Math.random()*(this.mods.length-1));
                    if (this.enemies[pick].equalsIgnoreCase("hh") && this.mods[mod].equalsIgnoreCase("L")) { // Healthy Helix should never be Large. That would be a game killer.
                        mod = 0;
                    }
                    s += ""+nr+" "+this.mods[mod]+this.enemies[pick]+"\n";
                }
            }
            s += "\n";
            if (i%bonus==0) {
                nr++;
            } else {
                pick++;
                if (pick > this.enemies.length-1) {
                    pick = 0;
                }
            }
            money += moneyInc;
            moneyInc += ((float)moneyIncEnd - (float)moneyIncStart)/(waveNr-1);
            hp *= growth;
            growth -= (growthStart-growthEnd)/(waveNr-1);
        }
        this.jTextPane1.setText(s);
    }
    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jButton1 = new javax.swing.JButton();
        jSpinner_paths = new javax.swing.JSpinner();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField_healthStart = new javax.swing.JTextField();
        jTextField_healthGrowthStart = new javax.swing.JTextField();
        jTextField_healthGrowthEnd = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jSpinner_moneyStart = new javax.swing.JSpinner();
        jSpinner_moneyIncStart = new javax.swing.JSpinner();
        jSpinner_moneyIncEnd = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        jSpinner_waves = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();
        jSpinner_nrEnemies = new javax.swing.JSpinner();
        jLabel10 = new javax.swing.JLabel();
        jSpinner_bonus = new javax.swing.JSpinner();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        jScrollPane1.setViewportView(jTextPane1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.weighty = 0.01;
        getContentPane().add(jScrollPane1, gridBagConstraints);

        jButton1.setText("Go");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(jButton1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jSpinner_paths, gridBagConstraints);

        jLabel1.setText("Paths");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jLabel1, gridBagConstraints);

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Health"));
        jLabel2.setText("Start");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel1.add(jLabel2, gridBagConstraints);

        jLabel3.setText("GrowthStart");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel1.add(jLabel3, gridBagConstraints);

        jLabel4.setText("GrowthEnd");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel1.add(jLabel4, gridBagConstraints);

        jTextField_healthStart.setText("jTextField1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel1.add(jTextField_healthStart, gridBagConstraints);

        jTextField_healthGrowthStart.setText("jTextField2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel1.add(jTextField_healthGrowthStart, gridBagConstraints);

        jTextField_healthGrowthEnd.setText("jTextField3");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel1.add(jTextField_healthGrowthEnd, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        getContentPane().add(jPanel1, gridBagConstraints);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Money"));
        jLabel5.setText("MoneyStart");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jLabel5, gridBagConstraints);

        jLabel6.setText("MoneyIncStart");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jLabel6, gridBagConstraints);

        jLabel7.setText("MoneyIncEnd");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jLabel7, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jSpinner_moneyStart, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jSpinner_moneyIncStart, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        jPanel2.add(jSpinner_moneyIncEnd, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.01;
        getContentPane().add(jPanel2, gridBagConstraints);

        jLabel8.setText("Waves");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jLabel8, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jSpinner_waves, gridBagConstraints);

        jLabel9.setText("Start # enemies");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jLabel9, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jSpinner_nrEnemies, gridBagConstraints);

        jLabel10.setText("Bonus every");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jLabel10, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        getContentPane().add(jSpinner_bonus, gridBagConstraints);

    }// </editor-fold>//GEN-END:initComponents
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.generate();
    }//GEN-LAST:event_jButton1ActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner jSpinner_bonus;
    private javax.swing.JSpinner jSpinner_moneyIncEnd;
    private javax.swing.JSpinner jSpinner_moneyIncStart;
    private javax.swing.JSpinner jSpinner_moneyStart;
    private javax.swing.JSpinner jSpinner_nrEnemies;
    private javax.swing.JSpinner jSpinner_paths;
    private javax.swing.JSpinner jSpinner_waves;
    private javax.swing.JTextField jTextField_healthGrowthEnd;
    private javax.swing.JTextField jTextField_healthGrowthStart;
    private javax.swing.JTextField jTextField_healthStart;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables
    
}
